package br.inf.ufrgs.usixml4cdc.document;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.parsers.DOMParser;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;


public class UsiXMLDocument {
	
	private final String uiModelIdentifier = "uiModel";
	private final String cuiModelIdentifier = "cuiModel";
	private final String auiModelIdentifier = "auiModel";
	private final String contextModelIdentifier = "contextModel";
	private final String resourceModelIdentifier = "resourceModel";
	
	private Element rootElement = null;
	
	private Element auiModelElement = null;
	private Element cuiModelElement = null;
	private Element contextModelElement = null;
	private Element resourceModelElement = null;
	
	
	/**
	 * Loads a UsiXML file and separates its main parts.
	 * 
	 * @param file
	 * @throws IOException 
	 * @throws JDOMException 
	 */
	public UsiXMLDocument(File file) throws IOException, ParserConfigurationException {
		DOMParser parser = new DOMParser();
		Document doc = null;
		try {
			parser.parse(file.getAbsolutePath());
			doc = parser.getDocument();
		} catch (SAXException e) {
			e.printStackTrace();
		}
		
		rootElement = (Element)doc.getElementsByTagName(this.uiModelIdentifier).item(0);
						
		this.auiModelElement = (Element)this.rootElement.getElementsByTagName(this.auiModelIdentifier).item(0);
		this.cuiModelElement = (Element)this.rootElement.getElementsByTagName(this.cuiModelIdentifier).item(0);
		this.contextModelElement = (Element)this.rootElement.getElementsByTagName(this.contextModelIdentifier).item(0);
		this.resourceModelElement = (Element)this.rootElement.getElementsByTagName(this.resourceModelIdentifier).item(0);
	}


	public Element getAuiModelElement() {
		return auiModelElement;
	}


	public Element getContextModelElement() {
		return contextModelElement;
	}


	public Element getCuiModelElement() {
		return cuiModelElement;
	}


	public Element getResourceModelElement() {
		return resourceModelElement;
	}
	
	public String getStringResourceContent(Element element){
		return null;
	}
	
	

}
